<?php 
include 'header.php'; 
?>

<h2><?= isset($edit) ? 'Edit' : 'Add' ?> Event</h2>

<?= isset($message) && !empty($message) ? '<div id="alert">' . $message . '</div>' : '' ?>

<form id="addcat" action="<?=base_url()?>index.php/admin/category/event<?= isset($edit) ? 'update' : 'add' ?>" method="POST">
    <div id="catname">Event Name: <input id="eventname" name="title" value="<?= isset($edit->title) ? $edit->title : '' ?>" /></div>
    <div id="eventdate">When: <input type="text" name="startdate" size="10" value="<?= isset($edit->start_date) ? $edit->start_date : '' ?>" id="startdate"/> to <input type="text" name="enddate" size="10" value="<?= isset($edit->end_date) ? $edit->end_date : '' ?>" id="enddate"/></div>
    
    <div id="desc">Description:<br /><textarea name="description"><?= isset($edit->description) ? $edit->description : '' ?></textarea></div>
    <?= isset($edit->catid) ? "<input type='hidden' name='id' value='" . $edit->catid . "' />" : "" ?>
    
    <div id="eventtype"><br />
    Event type:<br />
    <input id="featured" name="eventtype" value="featured" type="radio" <?= (isset($edit->discount_type) && $edit->discount_type == "featured") ? 'checked' : '' ?> /><label for="featured">Featured Product List (no discount)</label><br />
    <span class="eventtypedescription">This event is just a temporary collection of featured items in your inventory.</span><br />
    <span class="eventtypedescription">For instance, it can be <em>Newest Printers</em>, or <em>Oldies but Goodies</em>.</span><br />
    <input id="percentage" name="eventtype" value="percentage" type="radio" <?= (isset($edit->discount_type) && $edit->discount_type == "percentage") ? 'checked' : '' ?> /><label for="percentage">Percentage Discount: %</label><input name="percentagediscount" size="3" value="<?= (isset($edit->discount) && $edit->discount_type == "percentage") ? $edit->discount : '0' ?>" />
    <br />
    <span class="eventtypedescription">Discount every item in this event by a percentage. </span><br />
    <span class="eventtypedescription">For example, <em>Half Priced Printers!</em> will have a discount of %50.</span><br />
    <span class="eventtypedescription">Items are discounted only while the event is running.</span><br />
    <input id="dollar" name="eventtype" value="dollar" type="radio" <?= (isset($edit->discount_type) && $edit->discount_type == "dollar") ? 'checked' : '' ?> /><label for="dollar">Dollar-amount Discount $</label><input name="dollardiscount" size="3" value="<?= (isset($edit->discount) && $edit->discount_type == "dollar") ? $edit->discount : '0' ?>" />
    <br />
    <span class="eventtypedescription">Discount every item in this event by a dollar amount.</span><br />
    <span class="eventtypedescription">For example, <em>Save $10.00 on all Printers!</em> will have a discount of $10.</span><br />
    <span class="eventtypedescription">Items are discounted only while the event is running.</span><br />
    </div>
    
    <div id="buttons"><input type="submit" value="<?= isset($edit) ? 'Update' : 'Create' ?> Event" /> <input type="submit" name="Cancel" value="Cancel" /></div>
    
</form>
	<br />	
<h1>Events</h1>


<div id="content">
<form name="categoriesform" id="categoriesform" action="<?php echo base_url(); ?>index.php/admin/category/delete" method="POST">
		<div id="buttons">
			<input type="hidden" name="event" value="TRUE" />
			<input type="submit" name="button" value="Delete Selected" />
			
			<br />&nbsp;<br /><span style="display: none;" id="selecting">Select: <span id="selall"><a href="#" onclick="return false" style="color: black">All</a></span>, <span id="selnone"><a href="#" onclick="return false" style="color: black">None</a></span>
			</span>

		</div>

<table cellspacing=0 ><tbody id="the-list">
	<?php if (!empty($categories)) {
                foreach ($categories as $category) {
                
                        //Events only! Not categories!
                        if (in_array('Events', explode(' --- ', $category->sortname)) && $category->catname != "Events") {
                ?>
                
                
        
			<tr>	
		<td><input id="select_<?=$category->catid?>" name="checkall[<?=$category->catid?>]" value="<?=$category->catid?>" type="checkbox" /></td>

		<td class="date"><?=$category->count?> item<?= $category->count != 1 ? 's' : '' ?></td>
				<td class="pagetitle  <?php if ($enddates[$category->catid] < date("Y-m-d")) { echo 'invisible'; } ?>"><?= $category->tabs . anchor('admin/category/eventedit/' . $category->catid ,$category->catname, 'style="text-decoration: none"') ?>
					<span class="snippet"> <?= anchor('admin/category/eventedit/' . $category->catid , substr($category->description, 0, 55 - strlen($category->catname)), 'style="text-decoration: none; color: grey;"') ?><? $length = 55 - strlen($category->catname); ?><?= strlen($category->description) > $length  ? '...' : '' ?></span></td>
				<td class="author" style="text-align: right; padding-right: 25px"></td>
				<td><a href="<?php echo base_url(); ?>index.php/category/<?=$category->catid?>" title="View Category"><img src='<?php echo base_url(); ?>images/view.png' alt='view' /></a></td>
				<td><a href="<?php echo base_url(); ?>index.php/admin/category/eventedit/<?=$category->catid?>" title="Edit Event"><img src='<?php echo base_url(); ?>images/edit.png' alt='edit' /></a></td></td>
		
		</tr>
	<?php }}} ?>
			

			
<input type='hidden' name='offset' id='offset' value=<?php echo $offset; ?> />
</tbody>
</table>
</form>
<?php
include 'footer.php';
?>